import type { IObserver } from './interface/observer'

export default class Tts implements IObserver {
  execute(data: any) {
    return new Promise((resolve) => {
      console.log('我是TTS的数据', data)
      this.request().then((result) => {
        resolve({
          success: true,
        })
        this.play(result.message)
      })
    })
  }

  private request(): Promise<{ message: string }> {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          message: '拿到的文本',
        })
      }, 3000)
    })
  }

  private play(message: string) {
    console.log('我需要播放音频了', message)
  }

  destory() {
    console.log('tts销毁了')
  }
}
